package com.boot.study.service.impl;

import com.boot.study.domain.TestUser;
import com.boot.study.mapper.TestUserMapper;
import com.boot.study.service.TestUserService;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.service.impl.DiffParseFunction;
import com.mzt.logapi.starter.annotation.LogRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author likz
 * @Date 2025/1/22 15:28
 * @Description
 **/
@Service
public class TestUserServiceImpl implements TestUserService {

    @Resource
    TestUserMapper testUserService;

    @Override
    @LogRecord(type = "新增用户", success = "新增用户成功", fail = "新增用户失败", bizNo = "{{#testUser.id}}")
    public void save(TestUser testUser) {
        testUserService.insert(testUser);
        LogRecordContext.putVariable("user",testUser  );
    }

    @Override
    @LogRecord(type = "修改用户", success = "更新了{_DIFF{#testUser}", fail = "修改用户失败", bizNo = "{{#testUser.id}}",extra = "{{#testUser.toString()}}")
    public void update(TestUser testUser) {
        TestUser user = testUserService.selectById(testUser.getId());

        testUserService.updateById(testUser);
        LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, user);
        LogRecordContext.putVariable("user",user );
    }
}
